import Vue from 'vue';
import Vuex from 'vuex';


Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        user: sessionStorage.getItem('user') || '',
        token: sessionStorage.getItem('token') || '',
    },
    // 异步方法
    mutations: {
        /**
         * 向vuex存入userId信息
         */
        setUser(state, data) {
            state.user = data;
            sessionStorage.setItem('user', data);
        },
        setToken(state, data) {
            state.token = data;
            sessionStorage.setItem('token', data);
        }

    },
    // 同步方法
    actions: {},
    modules: {}
})
